package com.ylr.retrofitLearning.Interceptor;

import com.github.lianjiatech.retrofit.spring.boot.interceptor.BasePathMatchInterceptor;
import lombok.extern.slf4j.Slf4j;
import okhttp3.HttpUrl;
import okhttp3.Request;
import okhttp3.Response;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @ClassName TestInterceptor
 * @Description TODO  注解式拦截器
 * @Author ylr
 * @Date 2021/7/22 15:40
 * @Version 1.0
 */

@Component
@Slf4j
public class TestInterceptor extends BasePathMatchInterceptor {
    @Override
    protected Response doIntercept(Chain chain) throws IOException {
        log.info("拦截器起作用了");
        Request request = chain.request();
        HttpUrl url = request.url();
        log.info("拦截下的url: {}  ",url.toString());
        HttpUrl newUrl = url.newBuilder()
                .setPathSegment(2,"6143188.html")
                .build();
        log.info("新的url: {}  ",newUrl.toString());
        Request newRequest = request.newBuilder().url(newUrl).build();
        return chain.proceed(newRequest);

    }
}
